package com.weipai.springboot.module.mapper;

import com.weipai.springboot.model.IntegralGoods;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Qualifier;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;
import java.util.Map;

/**
 * 积分商品
 */
public interface IntegralGoodsMapper extends Mapper<IntegralGoods>, MySqlMapper<IntegralGoods>{

    //查询数据（或逻辑删除的数据）
    List<IntegralGoods> selectAllByDel(int del);

    //根据id查询积分商品
    IntegralGoods getIntegralGoodsById(String integralGoodsId);

    //批量删除
    int batchDeleteById(String[] id);
    
    //更改所需积分和状态
    @Update("update c_integral_goods set the_integral=#{theIntegral},integral_goods_status=#{integralStatus}, " +
            "update_time=date_format(now(), '%Y-%m-%d %H:%i:%s') where integral_goods_id=#{integralGoodsId}")
    int updateIntegralAndStatus(@Param("theIntegral") String theIntegral, @Param("integralStatus") String integralStatus, @Param("integralGoodsId") String integralGoodsId);

    //逻辑删除
    @Delete("update c_integral_goods set integral_goods_del=-1, del_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
            "where integral_goods_id=#{integralGoodsId}")
    int updateDel(String integralGoodsId);

    List<Map<String, Object>> selectAllByPage(@Param("start") Integer start, @Param("end") Integer size);

    List<Map<String, Object>> selectAllByPage22(@Param("start") Integer start, @Param("end") Integer size);


    Integer selectAllByPageAmount();
    Integer selectAllByPageAmount22();

    //修改所需积分和积分商品的状态
    int updateByPrimaryKeySelective22(IntegralGoods integralGoods);

    IntegralGoods selectByGoodsId(String goodsId);
}